package com.tinytoon.hunghoaqua;

import com.tinytoon.hunghoaqua.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class GameOverActivity extends Activity {

	public static int RESULT_PLAY_FROM_BEGIN 	= 1;
	public static int RESULT_REPLAY 			= 2;
	public static int RESULT_HIGH_SCORE 		= 3;
	public static int RESULT_RETURN 			= 4;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_over);
        int score = getIntent().getIntExtra("playerScore", 0);
        int level = getIntent().getIntExtra("GAME_LEVEL", 0);
        
        TextView tvLevel = (TextView)findViewById(R.id.ID_tv_game_level);
        tvLevel.setText("Bạn đã không qua bài " +level);
        TextView tvScore = (TextView)findViewById(R.id.ID_tv_game_score);
        tvScore.setText("Tổng điểm:" +score);
    }

    public void onReplay(View view){
    	setResult(RESULT_REPLAY);
    	finish();
    }
    
    public void onPlayFromBegin(View view){
    	setResult(RESULT_PLAY_FROM_BEGIN);
    	finish();
    }
    
    public void onHighScore(View view){
    	startActivity(new Intent(this, HighScoreActivity.class));
    	//finish();
    }
    
    public void onReturn(View view){
    	//return to MainActivity
    	setResult(RESULT_RETURN);//allow returns
    	finish();
    }
    
    public void onSave(View view){
    	//after selecting "save", disable name edit text and button save
    	EditText text = (EditText)this.findViewById(R.id.ID_et_name);
    	text.setFocusable(false);
    	Button btSave = (Button)this.findViewById(R.id.ID_btn_save);
    	btSave.setEnabled(false);
    	//get player name and score, then put into db	
    	String name = text.getText().toString();
    	if(name == null)
    		name = "Player";
    	int score = getIntent().getIntExtra("playerScore", 0);
    	DatabaseUtil db = new DatabaseUtil(this);
    	db.addRecord(score, name);
    }
    
}
